package com.line.tools.util;

import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletResponse;
import java.io.PrintWriter;

/**
 * Http请求响应工具类
 * 
 * @author Justin Yang
 * @version 1.0
 * @since 2016-07-12
 *
 */
public class ResponseUtils {
	private static Logger log = LoggerFactory.getLogger(ResponseUtils.class);

	/**
	 * 通过http响应，将结果集输出至界面
	 * 
	 * @param response
	 *            http响应
	 * @param obj
	 *            需要输出的json对象
	 */
	public static void writeJSON(HttpServletResponse response, JSONObject object) {
		try {
			response.setContentType("application/json;charset=utf-8");
			PrintWriter writer = response.getWriter();
			writer.write(object.toString());
			writer.flush();
			writer.close();
		} catch (Exception e) {
			log.info("Write reponse has exception:", e);
		}
	}

}
